package com.example.leaderapplication.Widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.leaderapplication.R;

public class BottonTabView extends LinearLayout {

    private Context mContext;
    private View mView;
    private ImageView imageView;
    private TextView textView;

    public BottonTabView(Context context) {
        this(context, null);
    }

    public BottonTabView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BottonTabView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.button_tab, this, true);
        imageView = (ImageView) mView.findViewById(R.id.iv_button_tab_image);
        textView = (TextView) mView.findViewById(R.id.iv_button_tab_text);

        TypedArray attributes = mContext.obtainStyledAttributes(attrs, R.styleable.BottonTabView);
        if (attributes != null) {
            int tapImage = attributes.getResourceId(R.styleable.BottonTabView_tab_image, R.drawable.shouye2);
            imageView.setImageResource(tapImage);

            int textColor = attributes.getColor(R.styleable.BottonTabView_tab_text_color, Color.BLACK);
            textView.setTextColor(textColor);

            String text = attributes.getString(R.styleable.BottonTabView_tab_text);
            textView.setText(text);
        }
        attributes.recycle();
    }

    public void setTabImage(int id) {
        imageView.setImageResource(id);
    }
    public void setTextColor(int color){
        textView.setTextColor(getResources().getColor(color));
    }
}
